package com.command.demo2.main;

import com.command.demo2.CeilingFan;
import com.command.demo2.Light;
import com.command.demo2.RemoteControlWithUndo;
import com.command.demo2.impl.CeilingFanHighCommand;
import com.command.demo2.impl.CeilingFanMediumCommand;
import com.command.demo2.impl.CeilingFanOffCommand;
import com.command.demo2.impl.LightOffCommand;
import com.command.demo2.impl.LightOnCommand;

/**
 * 支持撤销
 * 
 * @author Administrator
 * 
 */
public class RemoteLoader {

	public static void main(String[] args) {
		RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

		Light livingRoomLight = new Light("起居室");

		LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
		LightOffCommand livingRoomLightOff = new LightOffCommand(
				livingRoomLight);

		remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);

		remoteControl.onButtonWasPushed(0);
		remoteControl.offButtonWasPushed(0);
		System.out.println(remoteControl);
		remoteControl.undoButtonWasPushed();

		remoteControl.offButtonWasPushed(0);
		remoteControl.onButtonWasPushed(0);
		System.out.println(remoteControl);
		remoteControl.undoButtonWasPushed();

		CeilingFan ceilingFan = new CeilingFan("起居室");

		CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(
				ceilingFan);
		CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(
				ceilingFan);
		CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(
				ceilingFan);

		remoteControl.setCommand(0, ceilingFanMedium, ceilingFanOff);
		remoteControl.setCommand(1, ceilingFanHigh, ceilingFanOff);

		remoteControl.onButtonWasPushed(0);
		remoteControl.offButtonWasPushed(0);
		System.out.println(remoteControl);
		remoteControl.undoButtonWasPushed();

		remoteControl.onButtonWasPushed(1);
		System.out.println(remoteControl);
		remoteControl.undoButtonWasPushed();
	}
}
